package javase.javase02.io;

import java.io.*;

/**
 * @author: Gan
 * @date 2021/4/21 0021 20:44
 * @description: 序列化流与反序列化流
 **/
public class ObjectInputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
       // ObjectInputStream ois = new ObjectInputStream(new FileInputStream("a.txt"));
        ObjectOutputStream oos =
                new ObjectOutputStream(new FileOutputStream("a.txt"));
        Person p1 = new Person("小狗", 27);
        oos.writeObject(p1);
        oos.close();
    }
}

class Person implements Serializable {
    private static final long SerialVersionUID = 22L;
    private String name;
    private int age;

    public static Long getSerialVersionUID() {
        return SerialVersionUID;
    }

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}